/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.core.extensionpoints.palette;

import org.eclipse.core.runtime.IConfigurationElement;

import com.cea.papyrus.core.extensionpoints.AbstractExtensionPoint;
import com.cea.papyrus.core.utils.Debug;

/**
 * 
 */
public class Profile extends AbstractExtensionPoint {
	
	/**
	 * 
	 */
	public final IConfigurationElement	configElement;

	/**
	 * 
	 */
	private final String name;
	
	/**
	 * 
	 * 
	 * @param ordinal 	 * @param configElt 
	 * 
	 * @return 
	 */
	public static Profile parse(IConfigurationElement configElt) {
		
		if (!configElt.getName().equals(IConstants.TAG_PROFILE)) {
			return null;
		}
		
		try {
			return new Profile(configElt);
			
		} catch (Exception e) {
			
			String name = configElt.getAttribute(IConstants.ATT_PROFILE_NAME);
			if (name == null) {
				name = "[missing name attribute]";
			}
			String msg = "Failed to load property element named "
							+ name + " in "
							+ configElt
								.getDeclaringExtension()
								.getExtensionPointUniqueIdentifier();
			
			Debug.debug(null, msg, channel);
											
			return null;
		}
	}
	
	/**
	 * 
	 * 
	 * @param ordinal 	 * @param configElt 
	 */
	public Profile(IConfigurationElement configElt) {
		this.configElement = configElt;

		name  = getAttribute(configElt, IConstants.ATT_PROFILE_NAME, "undefined", true);
	}
	
	/**
	 * Default constructor.
	 * 
	 * @param uri 	 */
	public Profile() {
		this.configElement = null;
		
		name  = "undefined";
	}

	/**
	 * 
	 * 
	 * @return 
	 */
	public String getName() {
		return name;
	}

}
